
$(function() {


    $("#date").datebox('calendar').calendar({
        validator:function(beginDate){
            var date = new Date();
            return beginDate < date;
        }
    });
    toastr.options.positionClass = 'toast-center-center';

    //alert($("#rmbUser").switchbutton("options").checked);
    //回车事件
/*	$('#password').passwordbox('textbox').keydown(function (e) {
        if(e.keyCode == 13) {
           login();
        }
    });	*/
});

function consumeSave(){
    var cost = $("#cost").numberbox("getValue");
    var kinds = $("#kinds").combobox("getValue");
    var addr = $("#addr").textbox("getValue"); 
    var date = $("#date").datebox('getValue');
    var remark = $("#remark").textbox("getValue"); 
    

    if(cost.length == 0){
        $("#errMsgBar").show();
        $("#errMsgBar").html("请输入消费金额");
        return;
    }
    if(parseFloat(cost)==0){
        $("#errMsgBar").show();
        $("#errMsgBar").html("消费金额必需大于0");
        return;
    }
    if(kinds.length == 0){
        $("#errMsgBar").show();
        $("#errMsgBar").html("请选择消费种类");
        return;
    }

    if(addr.length == 0){
        $("#errMsgBar").show();
        $("#errMsgBar").html("请输入消费地点");
        return;
    }
    if(addr.length > 20){
        $("#errMsgBar").show();
        $("#errMsgBar").html("消费地点字符数量超过20");
        return;
    }

/*    if(password.length == 0){
        $("#errMsgBar").show();
        $("#errMsgBar").html("请输入密码");
        return;
    }*/

    if(date.length == 0){
        $("#errMsgBar").show();
        $("#errMsgBar").html("请选择消费日期");
        return;
    }    
    if(remark.length > 50){
        $("#errMsgBar").show();
        $("#errMsgBar").html("备注字符数量超过50");
        return;
    } 

      
    var param = {
        "cost":cost,
        "kinds":kinds,
        "addr":addr,
        "date":date,
        "remark":remark
        };
    //alert(JSON.stringify(param));
    
    $("#submitBtn").linkbutton('disable');

    $.ajax({
        type:"post",
        url:"/note/consume_save",
        contentType:"application/json;charset=utf-8",
        data:JSON.stringify(param),
        dataType:'json',
        success:function(ret){
            if(ret.code == 0){ //成功
               toastr.success("保存成功，正在跳转列表页面");
               setTimeout(function(){
                    window.location.href = "/note/consume_list";
                }, 2000);
               
            }else{
              //alert(ret.msg);
                $("#errMsgBar").show();
                $("#errMsgBar").html(ret.msg);
            }
        },
        error:function(ret) {
            toastr.error("保存失败");
        },
        complete:function () {
            $("#submitBtn").linkbutton('enable');
        }
    });    
}

